import {
  ApiPatientCardList,
    ApiGetSet
} from '../../api/index'
const app = getApp()
let {
  baseUrl,
  commonUpdate,
  commonUpload
} = app.globalData
Page({
  data: {
    baseUrl,
    commonUpdate,
    commonUpload
  },
  onLoad() {
    /*    this.getPatientList() */

  },
  onShow() {
    this.getUserInfo()
    this.getPatientList()
    this.getTabBar().init();
    this.getSet()

  },
  getSet(){
    ApiGetSet().then(res => {
      this.setData({
        getSet: res.data
      })
    })
  },
  getPatientList() {
    wx.showLoading({
      title: '加载中'
    })
    ApiPatientCardList().then(res => {
      this.setData({
        patientList: res.data
      })
      wx.hideLoading()
    })
  },
  //添加就诊卡
  createPatientCard() {
    let type = null
    if (this.data.patientList.length == 0) {
      type = 1
    }
    wx.navigateTo({
      url: `/pages/patientCard/index?type=${type}`,
    })
  },


  onEdit() {
    const item = this.data.userInfo
    wx.navigateTo({
      url: '/pages/userEdite/index?item=' + JSON.stringify(item),
    })
  },



  complaintsSuggestions() {
    wx.navigateTo({
      url: '/pages/complaintsSuggestions/index',
    })
  },
  //编辑就诊卡
  editPatient(e) {
    let value = e.currentTarget.dataset.v
    wx.navigateTo({
      url: `/pages/patientCardEdit/index?data=${JSON.stringify(value)}`,
    })
  },

  //退出登录
  exitLogin() {
    wx.showModal({
      title: "是否确认退出本系统？",
      success(res) {
        if (res.confirm) {
          app?.ws?.close()
          wx.clearStorage()
          wx.reLaunch({
            url: "/pages/login/index",
          })
        }
      }
    })

  },

  async getUserInfo() {
    this.setData({
      userInfo: wx.getStorageSync('userInfo'),
    }, () => {

    })
  },


  //完善信息
  /*   improveInformation() {

    }
   */

})
//editPatient